package cn.zhangjie.pet.service.impl;

import cn.zhangjie.basic.service.imp.BasicServiceImpl;
import cn.zhangjie.pet.domain.Pet;
import cn.zhangjie.pet.domain.PetDetail;
import cn.zhangjie.pet.mapper.PetDetailMapper;
import cn.zhangjie.pet.mapper.PetMapper;
import cn.zhangjie.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PetServiceImpl extends BasicServiceImpl<Pet> implements IPetService {
    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void add(Pet pet) {
        // 先添加pet，返回自增的主键
        petMapper.save(pet);

        // 再添加pet_datail
        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());
        petDetailMapper.save(petDetail);
    }

    @Override
    public void update(Pet pet) {
        petMapper.update(pet);
        petDetailMapper.update(pet.getPetDetail());
    }

    @Override
    public void del(Long id) {

        super.del(id);
        // 详情
        petDetailMapper.removeByPetId(id);
    }
    //上架
    @Override
    public void onsale(List<Long> ids) {
        Date date = new Date();
        petMapper.onsale(ids,date);
    }
    //下架
    @Override
    public void offsale(List<Long> ids) {
        Date date = new Date();
        petMapper.offsale(ids,date);
    }
}
